import java.io.IOException;

public class Parser {

	private static final String COMMAND_ADD = "add";
	//private static final String COMMAND_DISPLAY = "display";
	private static final String COMMAND_REMOVE = "remove";
	private static final String COMMAND_DATE = "date";
	private static final String COMMAND_EDIT = "edit";

	private static final String userInput = "add meet prof; 0930; 20121002";
	private static final String userInput6 = "add meet prof; 1; 0930; 20121002";
	private static final String userInput3 = "remove 1";
	private static final String userInput4 = "edit meet prof; 1; 0930; 20121002";
	private static final String userInput5 = "edit meet prof; 0930; 20121002";
	private static final String userInput1 = "date 20121002";
	

	public static void main(String[] args) throws IOException {

		parseUserInput();

	}

	public static void parseUserInput() {

		String[] getLength = userInput.split("; ");

		if (userInput.startsWith(COMMAND_ADD)){

			addMethod(getLength);
		}
		if (userInput.startsWith(COMMAND_EDIT)){
			
			editMethod(getLength);
		}

		if (userInput.startsWith(COMMAND_REMOVE)) {

			removeMethod();
		}
		if (userInput.startsWith(COMMAND_DATE)) {

			dateMethod();
		}

	}
	
	private static void addMethod(String[] getLength) {
		if (getLength.length == 3) {       

			splitCalInput();
		}

		else {

			splitPrioInput();
		}
	}

	private static Object[] splitPrioInput() {
		String[] parts = userInput.split(" ", 2);
		String command = parts[0];
		String theRest = parts[1];
		

		String[] array = theRest.split("; ");

		String desc = array[0];
		String prio = array[1];
		
		int prioInt = Integer.parseInt(prio);
		
		/*System.out.println("command: " + command);
		System.out.println("desc: " + desc);
		System.out.println("prio: " + prioInt);*/
		

		Object returnArray [] = new Object [3];
		returnArray [0] = command;
		returnArray [1] = desc;
		returnArray [2] = prioInt;			
						
		return returnArray;	
	}

	private static Object[] splitCalInput() {
		String[] parts = userInput.split(" ", 2);
		String command = parts[0];
		String theRest = parts[1];
		
		String[] array = theRest.split("; ");

		String desc = array[0];
		String time = array[1];
		String date = array[2];
		
		
		int timeInt = Integer.parseInt(time);
		int dateInt = Integer.parseInt(date);

		
		Object returnArray [] = new Object [4];
		returnArray [0] = command;
		returnArray [1] = desc;
		returnArray [2] = timeInt;
		returnArray [3] = dateInt;
		
		/*for (int i =0;i<returnArray.length; ++i ){
			
			System.out.print(returnArray[i]);
		}*/
				
		return returnArray;		
		
	}
	
	private static void editMethod(String[] getLength) {
		if (getLength.length == 3) {       

			splitCalInput();
		}

		else {

			splitPrioInput();
		}
	}
	
	private static Object[] removeMethod() {

		String[] array = userInput.split(" ");
		String command = array[0];
		String index = array[1];
		int indexInt = Integer.parseInt(index);

		/*System.out.println("command: " + command);
		System.out.println("index: " + indexInt);*/

		Object returnArray [] = new Object [3];
		returnArray [0] = command;
		returnArray [1] = indexInt;			
						
		return returnArray;
	}

	private static Object[] dateMethod() {

		String[] array = userInput.split(" ");
		String command = array[0];
		String date = array[1];
		int dateInt = Integer.parseInt(date);
/*
		System.out.println("command: " + command);
		System.out.println("date: " + dateInt);*/
		
		Object returnArray [] = new Object [3];
		returnArray [0] = command;
		returnArray [1] = dateInt;			
						
		return returnArray;

	}	
	
}
